package com.banade.learn.algorithm;

import java.util.HashMap;
import java.util.Map;

public class TwoSum {

    public  int[] twoSum2Bit(int[] nums, int target) {
        int max=0b11111111111;
        int [] test=new int[max+1];
        for (int i = 0; i < nums.length; i++) {
            int temp=target-nums[i];
            int pos=test[temp&max];
            if(pos!=0) return new int[]{pos-1,i};
            test[nums[i]&max]=i+1;
        }
       return null;
    }

    public  int[] twoSum2Map(int[] nums, int target) {
        Map<Integer,Integer> test = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int temp=target-nums[i];
            if(test.containsKey(temp)) return new int[]{test.get(temp),i};
            test.put(nums[i],i);
        }
       return null;
    }


}